package BundleMessage;

import BundleMessage.BundleDataActivity1;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.widget.Toolbar;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.example.myapplication.R;

public class BundleDataActivity2 extends AppCompatActivity {
  String userName;
  @Override protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.data_bundle_layout_2);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("Bundel数据传递2");
    setSupportActionBar(toolbar);
    ReciveBundleData();
    SetTipText();
    SetBackButtonListener();


  }
  private void SetBackButtonListener() {
    Button button = (Button) findViewById(R.id.back_button);
    button.setOnClickListener(new View.OnClickListener() {
      @Override public void onClick(View v) {
        BackToLastActivity();
      }
    });
  }
  private void BackToLastActivity() {
    Intent intent = new Intent(this, BundleDataActivity1.class);

    startActivity(intent);
  }

  private void SetTipText() {
    TextView textView = (TextView) findViewById(R.id.tip_text);
    String tipString = getString(R.string.current_user_message,userName);
    textView.setText(tipString);

  }
  private void ReciveBundleData() {
    Bundle bundle = getIntent().getExtras();
    userName = bundle.getString("name");

  }

}
